<template>
	<view class="beijingse" v-if="pageShow">
		<view class="mainpadding">
			<view class="dingwei flexcenter margin_top" @click="uploadImg(1,avatar,avatar_text)">
				<image class="touxiang" :src="avatar_text" mode=""></image>
				<image class="xianj" src="../static/images/system/xj.png" mode=""></image>
			</view>
		</view>
		<view class="mainpadding ffffff margin_top1 flexbetween">
			<view class="sanshier fonweight">姓名</view>
			<input class="textright" placeholder="请输入真实姓名" type="text" v-model="username"/>
		</view>
		<view class="mainpadding ffffff margin_top flexbetween" @click="changesex">
			<view class="sanshier fonweight">性别</view>
			<view class="flexright">
				<input class="textright" placeholder="请输入选择性别" type="text" disabled="" v-model="gender"/>
				<u-icon name="arrow-right" color="#C8C8C8"></u-icon>
			</view>
		</view>
		<view class="mainpadding ffffff margin_top flexbetween">
			<view class="sanshier fonweight">手机号</view>
			<view class="sanshier xiaohui">{{userinfo.mobile}}</view>
		</view>
		<view class="mainpadding ffffff margin_top flexbetween" @click="messageTime.timeShow = true">
			<view class="sanshier fonweight">出生年月</view>
			<view class="flexright">
				<input class="textright" placeholder="请选择出生年月" type="text" disabled="" v-model="birthday"/>
				<u-icon name="arrow-right" color="#C8C8C8"></u-icon>
			</view>
		</view>
		<view class="mainpadding ffffff margin_top flexbetween">
			<view class="sanshier fonweight">身份证号</view>
			<input class="textright" placeholder="请输入身份证号" type="text" v-model="idcard"/>
		</view>
		<view class="mainpadding ffffff margin_top flexbetween" @click="jumper('/pages_mypage/xiugaizhifubao')">
			<view class="sanshier fonweight">支付宝信息</view>
			<u-icon name="arrow-right" color="#C8C8C8"></u-icon>
		</view>
		<!--  -->
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="save()">保存</view>
		</view>
		<timePicker :messageTime="messageTime" @timeConfirm="timeConfirm"></timePicker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				pageShow:false,
				userinfo:{},
				avatar:"",
				avatar_text:"",
				username:"",
				gender:"",
				birthday:"",
				idcard:"",
				messageTime:{
					timeShow:false,
					title:"选择出生年月",
					mode:"date",//date日期，datetime年月日时分秒，time时间，year-month年月
					minDate:0//最小时间
				}
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			changesex(){
				let that = this
				uni.showActionSheet({
					itemList: ['男', '女'],
					success: function(res) {
						console.log(res);
						if (res.tapIndex == 0) {
							that.gender = "男"
						}
						if (res.tapIndex == 1) {
							that.gender = "女"
						}
					},
					fail: function(res) {}
				});
			},
			timeConfirm(e){
				this.birthday = e
			},
			save(){
				httpRequest.request('/api/user/profile', 'GET', {
					avatar:this.avatar,
					username:this.username,
					birthday:this.birthday,
					idcard:this.idcard,
					gender:this.gender=="男"?1:2,
				}).then(res => {
					httpRequest.toast(res.msg)
				})
			},
			init() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.avatar = res.data.avatar
					this.avatar_text = res.data.avatar_text
					this.username = res.data.username
					this.idcard = res.data.idcard
					this.gender = res.data.gender==1?"男":"女"
					this.birthday = res.data.birthday
					this.userinfo = res.data
					this.pageShow = true
				})
			},
			jumper(url) {
				uni.navigateTo({
					url: url
				})
			},
			uploadImg(value, upImgs,upImgs_text) {
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs,upImgs_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs,upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			uploadImageService(url, upImg,upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.avatar = res.url;
					this.avatar_text = image_item
					
				}).catch(err => {});
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.textarea{
		height: 100rpx;
	}
	.xianj {
		width: 46.13rpx;
		height: 46.13rpx;
		position: absolute;
		bottom: 0;
		right: 282rpx;
	}

	.touxiang {
		width: 182rpx;
		height: 182rpx;
		border-radius: 50%;
	}
</style>